// 初始样式
require('../../assets/css/index.less');
require('../../assets/css/basic.less');
// 小图标
require('../../assets/fonts/iconfont.css');
require('../../assets/font/iconfont.css');
// 当前页面样式
require('./mine.less');
// 引入weui
require("../../lib/weui/weui.css")
var weui = require("../../lib/weui/weui.js")
    // 轮播图
import Swiper, { Pagination, Autoplay } from 'swiper';
import 'swiper/swiper-bundle.css';
// 工具函数 utils
const dom = require('../../utils/dom');
var https = require('../../utils/https');
const local = require('../../utils/local');

dom.ready(function() {
    dom.creatfoot('mine');
    Swiper.use([Pagination, Autoplay]);
    new Swiper('.swiper', {
        // direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: true,
        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },

    });
    //  打卡
    function getClock() {
        https.get("/api/user/clockInInfo", function(res) {
            let { errno, data } = res;
            if (errno == 0) {
                dom.getEle("#clockBtn").innerHTML = data.isClockIn ? '已经打卡' : '今日打卡';
                dom.getEle("#clockCount").innerHTML = data.clockCount;
            }
        })
    }
    getClock();

    dom.addEvent("#clockBtn", "click", function() {
        https.post("/api/user/clockIn", {}, function(res) {
            if (res.errno == 0) {
                weui.alert("打卡成功");
                getClock();
            } else {
                weui.alert("打卡失败,今日已打卡");
            }
        })
    })

    // 个人信息
    function getMineInfo() {
        https.get("/api/user/info",
            function(res) {
                var { errno, data } = res;
                if (errno == 0) {
                    dom.getEle(".headimg").src = 'http://fitness.h5.itsource.cn:3701' + res.data.imgUrl;
                    dom.getEle(".username").innerHTML = res.data.nickName

                    dom.getEle(".personTxt").innerHTML = res.data.sign
                    console.log(data);
                    local.set("userData", data);
                }
            })
    };
    getMineInfo();

    // 个人动态
    dom.addEvent(".trends", "click", function() {
        location.href = './circle.html'
    });

    // 运动数据
    dom.addEvent(".sportdata", "click", function() {
        location.href = './sportData.html'
    });
    //  徽章
    dom.addEvent(".badge", "click", function() {
        location.href = './badges.html'
    });

})